
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 04/13/2016 13:36:27
-- Generated from EDMX file: H:\BaiduYunDownload\BRS项目\2016-1-5\BRS.BidModule\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ModelsDb];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_BBInfo_BidderInfo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BBInfo] DROP CONSTRAINT [FK_BBInfo_BidderInfo];
GO
IF OBJECT_ID(N'[dbo].[FK_BBInfo_tb_Bidder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BBInfo] DROP CONSTRAINT [FK_BBInfo_tb_Bidder];
GO
IF OBJECT_ID(N'[dbo].[FK_dbo_RoleRights_dbo_Rights_riid]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleRights] DROP CONSTRAINT [FK_dbo_RoleRights_dbo_Rights_riid];
GO
IF OBJECT_ID(N'[dbo].[FK_dbo_RoleRights_dbo_Roles_rid]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RoleRights] DROP CONSTRAINT [FK_dbo_RoleRights_dbo_Roles_rid];
GO
IF OBJECT_ID(N'[dbo].[FK_dbo_UserRoles_dbo_Roles_rid]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRoles] DROP CONSTRAINT [FK_dbo_UserRoles_dbo_Roles_rid];
GO
IF OBJECT_ID(N'[dbo].[FK_dbo_UserRoles_dbo_Users_uid]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRoles] DROP CONSTRAINT [FK_dbo_UserRoles_dbo_Users_uid];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[BBInfo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BBInfo];
GO
IF OBJECT_ID(N'[dbo].[BidderInfo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BidderInfo];
GO
IF OBJECT_ID(N'[dbo].[C__MigrationHistory]', 'U') IS NOT NULL
    DROP TABLE [dbo].[C__MigrationHistory];
GO
IF OBJECT_ID(N'[dbo].[LoginInfo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LoginInfo];
GO
IF OBJECT_ID(N'[dbo].[Rights]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rights];
GO
IF OBJECT_ID(N'[dbo].[RoleRights]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoleRights];
GO
IF OBJECT_ID(N'[dbo].[Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Roles];
GO
IF OBJECT_ID(N'[dbo].[tb_Bidder]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_Bidder];
GO
IF OBJECT_ID(N'[dbo].[tb_Project]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_Project];
GO
IF OBJECT_ID(N'[dbo].[tb_ProjectDetail]', 'U') IS NOT NULL
    DROP TABLE [dbo].[tb_ProjectDetail];
GO
IF OBJECT_ID(N'[dbo].[TenderMsg]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TenderMsg];
GO
IF OBJECT_ID(N'[dbo].[UserRoles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserRoles];
GO
IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'BBInfo'
CREATE TABLE [dbo].[BBInfo] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [BidderId] int  NOT NULL,
    [BidderInfoId] int  NOT NULL
);
GO

-- Creating table 'BidderInfo'
CREATE TABLE [dbo].[BidderInfo] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [IDCode] nvarchar(max)  NOT NULL,
    [Phone] nvarchar(max)  NOT NULL,
    [BidderType] nvarchar(max)  NOT NULL,
    [CreateDate] datetime  NULL
);
GO

-- Creating table 'C__MigrationHistory'
CREATE TABLE [dbo].[C__MigrationHistory] (
    [MigrationId] nvarchar(150)  NOT NULL,
    [ContextKey] nvarchar(300)  NOT NULL,
    [Model] varbinary(max)  NOT NULL,
    [ProductVersion] nvarchar(32)  NOT NULL
);
GO

-- Creating table 'Rights'
CREATE TABLE [dbo].[Rights] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NULL,
    [Module] nvarchar(max)  NULL,
    [Frm] nvarchar(max)  NULL,
    [btn] nvarchar(max)  NULL
);
GO

-- Creating table 'RoleRights'
CREATE TABLE [dbo].[RoleRights] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [riid] int  NOT NULL,
    [rid] int  NOT NULL,
    [AddTime] datetime  NOT NULL
);
GO

-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NULL,
    [IsDel] bit  NOT NULL,
    [AddTime] datetime  NOT NULL
);
GO

-- Creating table 'tb_Bidder'
CREATE TABLE [dbo].[tb_Bidder] (
    [ISID] int IDENTITY(1,1) NOT NULL,
    [Company] nvarchar(max)  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [IsBlack] bit  NULL,
    [BlackNote] nvarchar(max)  NULL,
    [FilePath] nvarchar(max)  NULL
);
GO

-- Creating table 'tb_Project'
CREATE TABLE [dbo].[tb_Project] (
    [ISID] int IDENTITY(1,1) NOT NULL,
    [ProjectName] nvarchar(max)  NOT NULL,
    [ProjectCode] nvarchar(max)  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [Note] nvarchar(max)  NOT NULL,
    [Leader] nvarchar(max)  NOT NULL,
    [FilePath] nvarchar(max)  NOT NULL,
    [Enabled] bit  NULL,
    [IsDone] bit  NULL,
    [Tender] nvarchar(max)  NULL,
    [TenderAgent] nvarchar(max)  NULL,
    [Deadline] datetime  NULL,
    [Deaddate] datetime  NULL
);
GO

-- Creating table 'tb_ProjectDetail'
CREATE TABLE [dbo].[tb_ProjectDetail] (
    [ISID] int IDENTITY(1,1) NOT NULL,
    [ProjectCode] nvarchar(max)  NOT NULL,
    [CompanyCode] nvarchar(max)  NOT NULL,
    [CreateDate] datetime  NOT NULL
);
GO

-- Creating table 'UserRoles'
CREATE TABLE [dbo].[UserRoles] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [uid] int  NOT NULL,
    [rid] int  NOT NULL,
    [IsDel] bit  NOT NULL,
    [AddTime] datetime  NOT NULL
);
GO

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [UserId] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(max)  NULL,
    [Password] nvarchar(max)  NULL,
    [UserCode] nvarchar(max)  NULL,
    [Enabled] bit  NOT NULL,
    [AddTime] datetime  NOT NULL,
    [UkeyCode] nvarchar(max)  NULL,
    [UkeyPassword] nvarchar(max)  NULL
);
GO

-- Creating table 'TenderMsg'
CREATE TABLE [dbo].[TenderMsg] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Type] nvarchar(50)  NOT NULL,
    [AddTime] datetime  NULL
);
GO

-- Creating table 'LoginInfo'
CREATE TABLE [dbo].[LoginInfo] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(max)  NULL,
    [LoginTime] datetime  NULL,
    [UserId] int  NULL,
    [Client] varchar(100)  NULL,
    [LoginOutTime] datetime  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'BBInfo'
ALTER TABLE [dbo].[BBInfo]
ADD CONSTRAINT [PK_BBInfo]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BidderInfo'
ALTER TABLE [dbo].[BidderInfo]
ADD CONSTRAINT [PK_BidderInfo]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [MigrationId], [ContextKey] in table 'C__MigrationHistory'
ALTER TABLE [dbo].[C__MigrationHistory]
ADD CONSTRAINT [PK_C__MigrationHistory]
    PRIMARY KEY CLUSTERED ([MigrationId], [ContextKey] ASC);
GO

-- Creating primary key on [Id] in table 'Rights'
ALTER TABLE [dbo].[Rights]
ADD CONSTRAINT [PK_Rights]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RoleRights'
ALTER TABLE [dbo].[RoleRights]
ADD CONSTRAINT [PK_RoleRights]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [ISID] in table 'tb_Bidder'
ALTER TABLE [dbo].[tb_Bidder]
ADD CONSTRAINT [PK_tb_Bidder]
    PRIMARY KEY CLUSTERED ([ISID] ASC);
GO

-- Creating primary key on [ISID] in table 'tb_Project'
ALTER TABLE [dbo].[tb_Project]
ADD CONSTRAINT [PK_tb_Project]
    PRIMARY KEY CLUSTERED ([ISID] ASC);
GO

-- Creating primary key on [ISID] in table 'tb_ProjectDetail'
ALTER TABLE [dbo].[tb_ProjectDetail]
ADD CONSTRAINT [PK_tb_ProjectDetail]
    PRIMARY KEY CLUSTERED ([ISID] ASC);
GO

-- Creating primary key on [Id] in table 'UserRoles'
ALTER TABLE [dbo].[UserRoles]
ADD CONSTRAINT [PK_UserRoles]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [UserId] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [Id] in table 'TenderMsg'
ALTER TABLE [dbo].[TenderMsg]
ADD CONSTRAINT [PK_TenderMsg]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'LoginInfo'
ALTER TABLE [dbo].[LoginInfo]
ADD CONSTRAINT [PK_LoginInfo]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [BidderInfoId] in table 'BBInfo'
ALTER TABLE [dbo].[BBInfo]
ADD CONSTRAINT [FK_BBInfo_BidderInfo]
    FOREIGN KEY ([BidderInfoId])
    REFERENCES [dbo].[BidderInfo]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_BBInfo_BidderInfo'
CREATE INDEX [IX_FK_BBInfo_BidderInfo]
ON [dbo].[BBInfo]
    ([BidderInfoId]);
GO

-- Creating foreign key on [BidderId] in table 'BBInfo'
ALTER TABLE [dbo].[BBInfo]
ADD CONSTRAINT [FK_BBInfo_tb_Bidder]
    FOREIGN KEY ([BidderId])
    REFERENCES [dbo].[tb_Bidder]
        ([ISID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_BBInfo_tb_Bidder'
CREATE INDEX [IX_FK_BBInfo_tb_Bidder]
ON [dbo].[BBInfo]
    ([BidderId]);
GO

-- Creating foreign key on [riid] in table 'RoleRights'
ALTER TABLE [dbo].[RoleRights]
ADD CONSTRAINT [FK_dbo_RoleRights_dbo_Rights_riid]
    FOREIGN KEY ([riid])
    REFERENCES [dbo].[Rights]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_dbo_RoleRights_dbo_Rights_riid'
CREATE INDEX [IX_FK_dbo_RoleRights_dbo_Rights_riid]
ON [dbo].[RoleRights]
    ([riid]);
GO

-- Creating foreign key on [rid] in table 'RoleRights'
ALTER TABLE [dbo].[RoleRights]
ADD CONSTRAINT [FK_dbo_RoleRights_dbo_Roles_rid]
    FOREIGN KEY ([rid])
    REFERENCES [dbo].[Roles]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_dbo_RoleRights_dbo_Roles_rid'
CREATE INDEX [IX_FK_dbo_RoleRights_dbo_Roles_rid]
ON [dbo].[RoleRights]
    ([rid]);
GO

-- Creating foreign key on [rid] in table 'UserRoles'
ALTER TABLE [dbo].[UserRoles]
ADD CONSTRAINT [FK_dbo_UserRoles_dbo_Roles_rid]
    FOREIGN KEY ([rid])
    REFERENCES [dbo].[Roles]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_dbo_UserRoles_dbo_Roles_rid'
CREATE INDEX [IX_FK_dbo_UserRoles_dbo_Roles_rid]
ON [dbo].[UserRoles]
    ([rid]);
GO

-- Creating foreign key on [uid] in table 'UserRoles'
ALTER TABLE [dbo].[UserRoles]
ADD CONSTRAINT [FK_dbo_UserRoles_dbo_Users_uid]
    FOREIGN KEY ([uid])
    REFERENCES [dbo].[Users]
        ([UserId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_dbo_UserRoles_dbo_Users_uid'
CREATE INDEX [IX_FK_dbo_UserRoles_dbo_Users_uid]
ON [dbo].[UserRoles]
    ([uid]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------